package com.aliwo.design.patterns.singleton;

import java.util.Random;

/**
 * @author xuyayuan
 * @description TODO
 * @date 2021/8/26 11:55
 */
public class TestStatic {
    public static void main(String[] args) {
        Child child = new Child();
        String node1 = "902901499021830183012309.node10";
        String node2 = "902901499021830183012309.node8";
        Long i = Long.valueOf(node1.split("node")[1]);
        System.out.println("i:"+i);
        System.out.println(Integer.valueOf(node1.split("node")[1])-Integer.valueOf(node2.split("node")[1]));
        //System.out.println("七位数字和字母组合："+TestStatic.getLowerCharAndNumber(7));
    }


    /**
     * 方法1：生成随机数字和字母组合
     * @param length
     * @return
     */
    public static String getLowerCharAndNumber(int length) {
        Random random = new Random();
        StringBuffer valSb = new StringBuffer();
        String charStr = "0123456789abcdefghijklmnopqrstuvwxyz";

        int charLen = charStr.length();

        //随机小写加数字
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(charLen);
            valSb.append(charStr.charAt(index));
        }
        return valSb.toString();
    }

    /**
     * 方法3：生成随机数字和字母组合
     * @param length
     * @return
     */
    public static String getCharAndNumr3(int length) {
        StringBuffer valSb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            String charOrNum = Math.round(Math.random()) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
            if ("char".equalsIgnoreCase(charOrNum)) {
                // 字符串
                int choice = Math.round(Math.random()) % 2 == 0 ? 65 : 97;  // 取得大写字母还是小写字母
                valSb.append((char) (choice + Math.round(Math.random()*25)));
            } else if ("num".equalsIgnoreCase(charOrNum)) {
                // 数字
                valSb.append(String.valueOf(Math.round(Math.random()*9)));
            }
        }
        return valSb.toString();
    }

}
